package com.yhny.lykj.yuhannongye.Adapter;

import android.graphics.Color;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.yhny.lykj.yuhannongye.R;
import com.yhny.lykj.yuhannongye.app.BaseRefreshListAdapter;
import com.yhny.lykj.yuhannongye.model.ShopTypeModel;

import java.util.List;

/**
 * ShopLeftListAdapter
 * 商城分类左侧列表
 */
public class ShopLeftListAdapter extends BaseRefreshListAdapter<ShopLeftListAdapter.ViewHolder> {
    private List<ShopTypeModel.ListEntity> list;
    private BaseRefreshListAdapter.OnItemClickListener listener = null;
    private int selectedPosition = 0;// 选中的位置
    public ShopLeftListAdapter(List<ShopTypeModel.ListEntity> list) {
        this.list = list;
    }

    @Override
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    protected void onBindBaseViewHolder(ViewHolder holder, int position) {
        final ShopTypeModel.ListEntity entity = list.get(position);
        holder.nameView.setText(""+entity.name);
        if (selectedPosition == position) {
            holder.nameView.setSelected(true);
            holder.nameView.setPressed(true);
            holder.nameView.setTextColor(Color.parseColor("#fda192"));
            holder.groupView.setBackgroundColor(Color.parseColor("#fda192"));
        } else {
            holder.nameView.setSelected(false);
            holder.nameView.setPressed(false);
            holder.nameView.setTextColor(Color.parseColor("#9f9f9f"));
            holder.groupView.setBackgroundColor( Color.parseColor("#ffffff"));
        }
    }

    @Override
    protected int getLayoutResId(int viewType) {

        return R.layout.item_shop_left;
    }

    @Override
    protected ViewHolder onCreateBaseViewHolder(View itemView) {
        return new ViewHolder(itemView, listener);
    }
    public void setSelectedPosition(int position) {
        selectedPosition = position;
        notifyDataSetChanged();
    }
    public static class ViewHolder extends BaseRefreshListAdapter.ViewHolder {

        private TextView nameView;
        private TextView groupView;

        public ViewHolder(View itemView, OnItemClickListener listener) {
            super(itemView, listener);
            nameView = (TextView) itemView.findViewById(R.id.item_pop_name);
            groupView = (TextView) itemView.findViewById(R.id.item_name_color);
        }
    }
}
